<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .cls {
            background-color: red;
        }
    </style>
</head>

<body class="cls" id="body">
    <input type="button" value="开关" id="btn">
    <script>
        // 类名方式：给body 添加移除类名
        //获取按钮
        var btn = document.getElementById('btn');
        //给按钮绑定点击事件
        btn.onclick = function() {
            //事件处理函数中，控制body标签的class类名---如果有则删除 没有就加上
            document.getElementById('body')
            if (body.className == '') {
                body.className = 'cls';
            } else {
                body.className = ''
            }
        }
    </script>
</body>

</html>